/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.Names;
/*     */ import com.zimbra.soap.admin.type.CacheEntryType;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvAlias
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  41 */     provUtil = new LdapProvTestUtil();
/*  42 */     prov = provUtil.getProv();
/*  43 */     domain = provUtil.createDomain(baseDomainName(), null);
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  48 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart) throws Exception {
/*  52 */     return createAccount(localPart, null);
/*     */   }
/*     */   
/*     */   private DistributionList createDistributionList(String localpart) throws Exception {
/*  56 */     return createDistributionList(localpart, null);
/*     */   }
/*     */   
/*     */   private DistributionList createDistributionList(String localPart, Map<String, Object> attrs) throws Exception
/*     */   {
/*  61 */     return provUtil.createDistributionList(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private void deleteDistributionList(DistributionList dl) throws Exception {
/*  65 */     provUtil.deleteDistributionList(dl);
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart, Map<String, Object> attrs) throws Exception
/*     */   {
/*  70 */     return provUtil.createAccount(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private void deleteAccount(Account acct) throws Exception {
/*  74 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void addAccountAlias() throws Exception {
/*  79 */     String ACCT_NAME_LOCALPART = Names.makeAliasNameLocalPart(genAcctNameLocalPart("acct"));
/*  80 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/*  81 */     String ACCT_ID = acct.getId();
/*     */     
/*  83 */     String ALIAS_LOCALPART = Names.makeAliasNameLocalPart(genAcctNameLocalPart("alias"));
/*  84 */     String ALIAS_NAME = TestUtil.getAddress(ALIAS_LOCALPART, domain.getName());
/*     */     
/*  86 */     prov.addAlias(acct, ALIAS_NAME);
/*     */     
/*  88 */     prov.flushCache(CacheEntryType.account, null);
/*  89 */     Account acctByAlias = prov.get(Key.AccountBy.name, ALIAS_NAME);
/*     */     
/*  91 */     Assert.assertEquals(ACCT_ID, acctByAlias.getId());
/*     */     
/*  93 */     deleteAccount(acctByAlias);
/*     */     
/*     */ 
/*  96 */     prov.flushCache(CacheEntryType.account, null);
/*  97 */     acctByAlias = prov.get(Key.AccountBy.name, ALIAS_NAME);
/*  98 */     Assert.assertNull(acctByAlias);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void removeAccountAlias() throws Exception {
/* 103 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("acct"));
/* 104 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 105 */     String ACCT_ID = acct.getId();
/*     */     
/* 107 */     String ALIAS_LOCALPART = Names.makeAliasNameLocalPart(genAcctNameLocalPart("alias"));
/* 108 */     String ALIAS_NAME = TestUtil.getAddress(ALIAS_LOCALPART, domain.getName());
/*     */     
/* 110 */     prov.addAlias(acct, ALIAS_NAME);
/*     */     
/* 112 */     prov.flushCache(CacheEntryType.account, null);
/* 113 */     Account acctByAlias = prov.get(Key.AccountBy.name, ALIAS_NAME);
/*     */     
/* 115 */     Assert.assertEquals(ACCT_ID, acctByAlias.getId());
/*     */     
/* 117 */     prov.removeAlias(acct, ALIAS_NAME);
/*     */     
/* 119 */     prov.flushCache(CacheEntryType.account, null);
/* 120 */     acctByAlias = prov.get(Key.AccountBy.name, ALIAS_NAME);
/*     */     
/* 122 */     Assert.assertNull(acctByAlias);
/*     */     
/* 124 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void addDistributionListAlias() throws Exception {
/* 129 */     String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart("dl"));
/* 130 */     DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
/* 131 */     String DL_ID = dl.getId();
/*     */     
/* 133 */     String ALIAS_LOCALPART = Names.makeAliasNameLocalPart(genGroupNameLocalPart("alias"));
/* 134 */     String ALIAS_NAME = TestUtil.getAddress(ALIAS_LOCALPART, domain.getName());
/*     */     
/* 136 */     prov.addAlias(dl, ALIAS_NAME);
/*     */     
/* 138 */     prov.flushCache(CacheEntryType.account, null);
/* 139 */     DistributionList dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
/*     */     
/* 141 */     Assert.assertEquals(DL_ID, dlByAlias.getId());
/*     */     
/* 143 */     deleteDistributionList(dlByAlias);
/*     */     
/*     */ 
/* 146 */     prov.flushCache(CacheEntryType.group, null);
/* 147 */     dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
/* 148 */     Assert.assertNull(dlByAlias);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void removeDistributionListAlias() throws Exception {
/* 153 */     String DL_NAME_LOCALPART = Names.makeDLNameLocalPart(genGroupNameLocalPart("dl"));
/* 154 */     DistributionList dl = createDistributionList(DL_NAME_LOCALPART);
/* 155 */     String DL_ID = dl.getId();
/*     */     
/* 157 */     String ALIAS_LOCALPART = Names.makeAliasNameLocalPart(genGroupNameLocalPart("alias"));
/* 158 */     String ALIAS_NAME = TestUtil.getAddress(ALIAS_LOCALPART, domain.getName());
/*     */     
/* 160 */     prov.addAlias(dl, ALIAS_NAME);
/*     */     
/* 162 */     prov.flushCache(CacheEntryType.group, null);
/* 163 */     DistributionList dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
/*     */     
/* 165 */     Assert.assertEquals(DL_ID, dlByAlias.getId());
/*     */     
/* 167 */     prov.removeAlias(dl, ALIAS_NAME);
/*     */     
/* 169 */     prov.flushCache(CacheEntryType.group, null);
/* 170 */     dlByAlias = prov.get(Key.DistributionListBy.name, ALIAS_NAME);
/*     */     
/* 172 */     Assert.assertNull(dlByAlias);
/*     */     
/* 174 */     deleteDistributionList(dl);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvAlias.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */